package en.edu.zxj.rabbit.extensions.demo.listener;

import com.rabbitmq.client.Channel;
import en.edu.zxj.rabbit.extensions.demo.constant.Constants;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;
import java.util.Date;


/**
 * Created with IntelliJ IDEA.
 * Description：
 *
 * @author: zxj
 * @date: 2024-09-21
 * @time: 20:56:45
 */
@Component
public class DelayQueueListener {
    @RabbitListener(queues = Constants.DELAY_QUEUE_NAME)
    public void listenerDelayQueue(Message message, Channel channel) {
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        System.out.printf("%tc 延迟队列接收到消息: %s, deliveryTag: %d%n",
                new Date(), new String(message.getBody(), StandardCharsets.UTF_8),
                message.getMessageProperties().getDeliveryTag());
    }
}

